package com.computer.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.computer.cart.Cart;
import com.computer.datebase.DateBase;
import com.computer.product.Computer;



@WebServlet("/cart")
public class CartServlet extends HttpServlet {
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String brand = request.getParameter("brand");
		Computer p = DateBase.getOne(brand);
		HttpSession session = request.getSession();
		Object obj = session.getAttribute("cart");
		Cart cart;
		if(obj == null) {
			cart = new Cart();
		}else {
			cart = (Cart)obj;
		}
		cart.addProduct(p);
		
		session.setAttribute("cart", cart);
		response.sendRedirect("selectproduct");
	}
    

}















